<template>
  <div class="app-container-item">
    <div class="form-main" style="height: calc(100vh - 240px);">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属分类" prop="modelType">
              <el-select v-model="form.modelType" placeholder="请选择模块类型" disabled>
                <el-option
                  v-for="item in dict.report_model_type"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分组名称" prop="groupName">
              <el-input v-model="form.groupName" placeholder="请输入分组名称" :disabled="disabled"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序序号" prop="orderNum">
              <el-input v-model="form.orderNum" placeholder="请输入排序序号" :disabled="disabled"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入内容" :disabled="disabled"/>
            </el-form-item>
          </el-col>
        </el-row>
        <config-index ref="configRef" :groupForm="form"/>
      </el-form>
    </div>
    <div class="dialog-footer" style="text-align: center;">
      <el-button type="primary" plain @click="submitForm" v-hasPermi="['ureport:reportGroup:edit']">保 存</el-button>
    </div>
  </div>
</template>

<script>

  import {getReportGroup, addReportGroup, updateReportGroup} from "@/api/ureport/reportGroup";
  import ConfigIndex from "../config/index"
  export default {
    name: "GroupFrom",
    components:{ ConfigIndex },
    dicts: ['report_model_type',],
    data() {
      return {
        //是否禁用
        disabled: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          modelType: [
            { required: true, message: "所属分类不能为空", trigger: "blur" }
          ],
          groupName: [
            { required: true, message: "分组名称不能为空", trigger: "blur" }
          ],
        }
      };
    },
    watch: {
      currentNode(v) {
        this.initForm()
      }
    },
    created() {
      this.initForm()
    },
    methods: {
      initForm() {
        this.reset();
        if (this.currentNode.modelType == 'group') {
          getReportGroup(this.currentNode.id).then(res => {
            this.form = res.data
          });
        }
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          modelType: null,
          groupName: null,
          orderNum: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            updateReportGroup(this.form).then(response => {
              this.msgSuccess("修改所属分组成功");
              this.open = false;
              this.$emit("ok")
            });
          }
        });
      },
    },
    props: {
      currentNode: {
        type: Object,
        default:()=>{}
      },
    }
  };
</script>
